﻿using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;
using Const;
using Entitas;
using Services;
using UnityEngine;

public class CreateService
{
    private static CreateService _instance;
    private Contexts _contexts;
    
    
    public static CreateService Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance= new CreateService();
            }

            return _instance;
        }
    }

   
    public void Init(Contexts contexts)
    {
        _contexts = contexts;
    }
    
    
    public GameEntity CreateGameBoard()
    {
        GameEntity entity = _contexts.game.CreateEntity();
        entity.AddComponentsGameBoardComponents(8,9);
        return entity;
    }

    /// <summary>
    /// 创建Item
    /// </summary>
    public void CreateRandomItem(customData index)
    {
        var entity = Contexts.sharedInstance.game.CreateEntity();
        entity.isComponentsItem = true;
        entity.isComponentsMovable = true;
        entity.AddComponentsItemIndex(index);
        entity.ReplaceComponentsItemEffectState(ItemEffectName.NONE);
        entity.ReplaceComponentsFallState(fallState.STEADY);
        entity.AddComponentsLoadPrefab(ResPath.PrefabPath+RandomPathService.RandomPath());
    }
    /// <summary>
    /// 创建block
    /// </summary>
    public void CreateBlock(customData index)
    {
        var entity = Contexts.sharedInstance.game.CreateEntity();
        entity.isComponentsItem = true;
        entity.isComponentsMovable = false;
        entity.AddComponentsItemIndex(index);
        entity.AddComponentsLoadPrefab(ResPath.BlockPath);
        entity.ReplaceComponentsItemEffectState(ItemEffectName.NONE);
    }
    
    public void CreateItem(int nameIndex,int x,int y)
    {
        var entity = Contexts.sharedInstance.game.CreateEntity();
        entity.isComponentsItem = true;
        entity.isComponentsMovable = true;
        entity.AddComponentsItemIndex(new customData(x,y));
        entity.ReplaceComponentsItemEffectState(ItemEffectName.NONE);
        entity.ReplaceComponentsFallState(fallState.STEADY);
        entity.AddComponentsLoadPrefab(ResPath.PrefabPath+"Item"+nameIndex);
    }
    
    
}
